home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / DropInfo ƒ / DI⁄P / DSUserProcs.p < prev    next >
Encoding:
Text File  |  1991-12-22  |  7.4 KB  |  238 lines  |  [TEXT/MPS ]

  1. {******************************************************************************
  2. **
  3. **  Project Name:    DropInfo
  4. **     File Name:    DSUserProcs.p
  5. **
  6. **   Description:    Specific AppleEvent handlers used by the Dropbox
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **
  16. *******************************************************************************
  17. **                      R E V I S I O N   H I S T O R Y
  18. *******************************************************************************
  19. **
  20. **      Date        Time    Author    Description
  21. **    --------    -----    ------    ---------------------------------------------
  22. **    12/22/91            LDR        Modified for use in Drop•Info
  23. **    12/09/91            LDR        Added the new SelectFile & UserGlobal userProcs
  24. **                                Modified PostFlight to only autoquit on odoc, not pdoc
  25. **    11/24/91            LDR        Added the userProcs for pdoc handler
  26. **                                Added support for a userDataHandle passed odoc/pdoc routines
  27. **                                We now include the new DSUtils
  28. **    10/30/91            LDR        Modified USES clause for new include & ifc'ed ThP
  29. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  30. **                                Added a bunch of comments for clarification
  31. **    04/08/91    23:58    LDR        Original Version
  32. **
  33. ******************************************************************************}
  34.  
  35. UNIT DSUserProcs;
  36. INTERFACE
  37.  
  38. {$IFC THINK_Pascal}
  39.     USES
  40.         DSGlobals, DSUtils, DIStuff;    {just the DropShell files}
  41. {$ELSEC}
  42.     USES
  43.     { First load standard interface files}
  44.         MemTypes, QuickDraw, 
  45.  
  46.     { Now include the stuff from OSIntf }
  47.         OSIntf, 
  48.  
  49.     { Now Include the stuff from ToolIntf.p }
  50.         ToolIntf, Packages, GestaltEqu, 
  51.  
  52.     { Then any OTHER Toolbox interfaces... }
  53.         Files, Aliases, AppleEvents,
  54.  
  55.     { And finally any files from DropShell }
  56.         DSGlobals, DSUtils, DIStuff;
  57. {$ENDC THINK_Pascal}
  58.     
  59. {---------------------}
  60. {Interface Definitions}
  61. {---------------------}
  62.  
  63.     PROCEDURE InstallOtherEvents;
  64.     
  65.     PROCEDURE OpenApp;
  66.     PROCEDURE QuitApp;
  67.     
  68.     FUNCTION  PreFlightDocs(opening: Boolean; VAR userDataHandle: UNIV Handle): Boolean;
  69.     PROCEDURE OpenDoc( myFSSPtr: FSSpecPtr; opening: Boolean; userDataHandle: UNIV Handle );
  70.     PROCEDURE PostFlightDocs(opening: Boolean; userDataHandle: UNIV Handle);
  71.  
  72.     PROCEDURE SelectFile;
  73.     FUNCTION  InitUserGlobals:Boolean;
  74.     PROCEDURE DisposeUserGlobals;
  75.     
  76. IMPLEMENTATION
  77.  
  78. {$S AEVT}
  79.  
  80.     {
  81.         This routine is called during init time.
  82.         
  83.         It allows you to install more AEVT Handlers beyond the standard four
  84.     }
  85.     PROCEDURE InstallOtherEvents;
  86.     BEGIN
  87.     END;
  88.     
  89.     {
  90.         This routine is called when an OAPP event is received.
  91.         
  92.         Currently, all it does is set the gOApped flag, so you know that
  93.         you were called initally with no docs, and therefore you shouldn't 
  94.         quit when done processing any following odocs.
  95.     }
  96.     PROCEDURE OpenApp;
  97.     BEGIN
  98.         gOApped := TRUE;
  99.     END;
  100.     
  101.     {
  102.         This routine is called when an QUIT event is received.
  103.         
  104.         We simply set the global done flag so that the main event loop can
  105.         gracefully exit.  We DO NOT call ExitToShell for two reasons:
  106.         1) It is a pretty ugly thing to do, but more importantly
  107.         2) The Apple event manager will get REAL upset!
  108.     }
  109.     PROCEDURE QuitApp;
  110.     BEGIN
  111.         gDone := TRUE;    {All Done!}
  112.     END;
  113.     
  114.     {
  115.         This routine is the first one called when an ODOC or PDOC event is received.
  116.         
  117.         In this routine you would place code used to setup structures, etc. 
  118.         which would be used in a 'for all docs' situation (like "Archive all
  119.         dropped files"). 
  120.         
  121.         Obviously, the opening boolean tells you whether you should be opening
  122.         or printing these files based on the type of event recieved.
  123.         
  124.         userDataHandle is a handle that you can create & use to store your own
  125.         data structs.  This dataHandle will be passed around to the other 
  126.         odoc/pdoc routines so that you can get at your data without using
  127.         globals - just like the new StandardFile.    The shell knows NOTHING
  128.         about this userDataHandle and will do NOTHING to do.  You MUST perform
  129.         all allocation, access and deallocation if you use it.
  130.     
  131.         We also return a boolean to tell the caller if you support this type
  132.         of event.  By default, our dropboxes don't support the pdoc, so when
  133.         opening is FALSE, we return FALSE to let the caller send back the
  134.         proper error code to the AEManager.
  135.     }
  136.     FUNCTION PreFlightDocs(opening: Boolean; VAR userDataHandle: UNIV Handle): Boolean;
  137.     BEGIN
  138.     
  139.         PreFlightDocs := opening;    {we support opening, but not printing - see above}
  140.     END;
  141.     
  142.     {
  143.         This routine is called for each file passed in the ODOC or PDOC event.
  144.         
  145.         In this routine you would place code for processing each file/folder/disk that
  146.         was dropped on top of you.
  147.     }
  148.     PROCEDURE OpenDoc( myFSSPtr: FSSpecPtr; opening: Boolean; userDataHandle: UNIV Handle );
  149.     BEGIN
  150.         IF (opening) THEN        { only do on an open, NOT a print! }
  151.             GetTheInfo(myFSSPtr);
  152.     END;
  153.     
  154.     {
  155.         This routine is the last routine called as part of an ODOC or PDOC event.
  156.         
  157.         In this routine you would place code to process any structures, etc. 
  158.         that you setup in the PreflightDocs routine.
  159.  
  160.         If you created a userDataHandle in the PreFlightDocs routines, this is
  161.         the place to dispose of it since the Shell will NOT do it for you!
  162.     }
  163.     PROCEDURE PostFlightDocs(opening: Boolean; userDataHandle: UNIV Handle);
  164.     BEGIN
  165.  
  166.         {reset some dropInfo specific globals}
  167.         gChgAll        := FALSE;
  168.         gWarned     := FALSE;
  169.         gOnlyOne    := FALSE;
  170.  
  171.         IF (opening) AND (NOT gOApped) THEN
  172.             gDone := TRUE;    {close everything up when sent an original odoc}
  173.         
  174.         {
  175.             The reason we do not auto quit is based on a recommendation in the
  176.             Apple event Registry which specifically states that you should NOT
  177.             quit on a 'pdoc' as the Finder will send you a 'quit' when it is 
  178.             ready for you to do so.
  179.         }
  180.     END;
  181.  
  182.  
  183.  
  184.     {
  185.         This routine is called when the user chooses "Select File…" from the
  186.         File Menu.
  187.         
  188.         Currently it simply calls the new StandardGetFile routine to have the
  189.         user select a single file (any type, numTypes = -1) and then calls the
  190.         SendODOCToSelf routine in order to process it.  
  191.                 
  192.         The reason we send an odoc to ourselves is two fold: 1) it keeps the code
  193.         cleaner as all file openings go through the same process, and 2) if events
  194.         are ever recordable, the right things happen (this is called Factoring!)
  195.  
  196.         Modification of this routine to only select certain types of files, selection
  197.         of multiple files, and/or handling of folder & disk selection is left 
  198.         as an exercise to the reader.
  199.     }
  200.     PROCEDURE SelectFile;
  201.     VAR
  202.         stdReply: StandardFileReply;
  203.         theTypeList: SFTypeList;
  204.     BEGIN
  205.         StandardGetFile(NIL, -1, theTypeList, stdReply);
  206.         IF (stdReply.sfGood) THEN                {user did not cancel}
  207.             SendODOCToSelf(stdReply.sfFile);    {so send me an event!}
  208.     END;
  209.  
  210. {
  211.     This routine is called during the program's initialization and gives you
  212.     a chance to allocate or initialize any of your own globals that your
  213.     dropbox needs.
  214.     
  215.     You return a boolean value which determines if you were successful.
  216.     Returning false will cause DropShell to exit immediately.
  217. }
  218. FUNCTION InitUserGlobals:Boolean;
  219. BEGIN
  220.     gChgAll        := FALSE;
  221.     gWarned     := FALSE;
  222.     gOnlyOne    := FALSE;
  223.     
  224.     InitUserGlobals := TRUE;    {not much to do, so we must be successful!}
  225. END;
  226.  
  227. {
  228.     This routine is called during the program's cleanup and gives you
  229.     a chance to deallocate any of your own globals that you allocated 
  230.     in the above routine.
  231. }
  232. PROCEDURE DisposeUserGlobals;
  233. BEGIN
  234.     {nothing to do for our sample dropbox}
  235. END;
  236.     
  237. END.
  238.